package com.homegoods.home.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.homegoods.home.R;
import com.kedll.library.util.MyUtils;

public class HomeLabelTextView extends FrameLayout {
    private TextView tvLabel;
    private TextView tvTitle;
    private String titleName;

    public HomeLabelTextView(Context context) {
        this(context, null);
    }

    public HomeLabelTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public HomeLabelTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
        initAttrs(context, attrs);
    }

    private void initAttrs(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.HomeLabelTextView);
        titleName = typedArray.getString(R.styleable.HomeLabelTextView_home_title_name);
        MyUtils.calculateTag(tvLabel, tvTitle, titleName);
        if (!TextUtils.isEmpty(titleName)) {
            tvTitle.setText(titleName);
        }
    }

    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.home_label_layout, this, true);
        tvLabel = findViewById(R.id.tv_label);
        tvTitle = findViewById(R.id.tv_title1);
    }
}
